package cn.haohaowo;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by luwancai on 18/5/29.
 * DESC:
 */
@Slf4j
@RestController
public class LeaderController {

    @Autowired
    @Qualifier("haoShopKafkaTemplate")
    private KafkaTemplate kafkaTemplate;

    @ResponseBody
    @RequestMapping("/runFollowers.do")
    public String runFollowers(String runLists) {

        log.info("Param runLists: {}", runLists);
        JSONObject result = new JSONObject();
        try {
            //发送启动节点的列表
            kafkaTemplate.send("stockfollower", runLists);
            result.put("isSuccess", true);
        } catch (Exception e) {
            log.error("Service runFollowers error: {}", e.getMessage(), e);
            result.put("isSuccess", false);
        }
        log.info("Return result: {}", result.toJSONString());

        return result.toJSONString();

    }

}
